<template>
	<view class="p30">
		<p class="title">
			撰写店铺公告，方便用户更好的了解我们~
		</p>
		<view class="content p30">
			<textarea v-model="contents" placeholder="上新活动/优惠/其他 " maxlength="200" />
			<p class="length">
				<view @tap="contents = '' " class="fl c-red">清空</view>
				{{lens}}/200字
			</p>
		</view>
		<button @tap="send()" class="btnbg text-lg br42"> 确认提交</button>
	</view>
</template>

<script>
	import {updateStoreInfo,storeinfo} from '@/api/api.js'
	export default {
		data() {
			return {
				shakeState:0,
				contents:''
			};
		},
		onLoad() {
			this.init()
		},
		methods:{
			async init(){
				let data = await storeinfo()
				if(data.data.notice != null){
					this.contents = data.data.notice
				} 
			},
			async send(){
				let data = {
					"notice": this.contents
				}
				if(this.shakeState == 0){
					this.shakeState = 1
					let state = await updateStoreInfo(data)
					if(state.code == 0){
						uni.redirectTo({
							url:'../publicNewsSuccess/publicNewsSuccess'
						}) 
					}else{
						this.shakeState = 0
					} 		
				}
				
			}
		},
		computed:{
			  lens(){
				return this.contents.length;
			}
		}
	}
</script>

<style lang="less" scoped>
@import './index.less';
</style>
